package com.example.practice.service.impl;

import com.example.practice.dao.UserDao;
import com.example.practice.entity.User;
import com.example.practice.service.UserService;
import com.example.practice.utls.SessionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表服务实现类
 *
 * @author makejava
 * @since 2023-12-20 21:32:57
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    @Override
    public Integer login(User user) {
        User user1=new User();
        user1.setAccount(user.getAccount());
        List<User> userinfos = this.userDao.queryAllByLimit(user1);
        if(userinfos.size()==0){
            return 400;
            //no
        }else {
            if(userinfos.get(0).getPasswd().equals(user.getPasswd())){
                SessionUtils.saveCurrentUserInfo(userinfos.get(0));
                 return userinfos.get(0).getRole();
                //成功
            }
            else {
                return 500;
                //密码错误
            }
        }
    }


    @Override
    public User getUserByAccount(String account){
        return this.userDao.getUserByAccount(account);
    }


    @Override
    public Integer updateUser(User user){
        return this.userDao.updateUser(user);
    }
    @Override
    public List<User>getCheckStudent(Integer uid){
        return this.userDao.getCheckStudent(uid);
    }

    @Override
    public User getName(Integer id) {
        return this.userDao.getName(id);
    }

    @Override
    public User getByFid(Integer fid) {
        return this.userDao.getByFid(fid);
    }

    @Override
    public String getByUid(Integer uid) {
        return this.userDao.getByUid(uid);
    }

    @Override
    public List<User> getDistName() {
        return this.userDao.getDistName();
    }
    public List<User> getUserByActivity(Integer aid){return this.userDao.getUserByActivity(aid);}

    @Override
    public Integer insertStudentSchool(Integer uid, Integer aid, String sname){return this.userDao.insertStudentSchool(uid,aid,sname);}

    @Override
    public String selectStudentSchool(Integer uid,Integer aid){return this.userDao.selectStudentSchool(uid,aid);}

    @Override
    public Integer saveUserUrl(Integer uid, String url){return this.userDao.saveUserUrl(uid,url);}
    @Override
    public String selectUserUrl(Integer uid){return this.userDao.selectUserUrl(uid);}
    @Override
    public Integer deleteStudentSchool(Integer uid,Integer aid){return this.userDao.deleteStudentSchool(uid,aid);}

    @Override
    public Integer insertUser(List<User> users) {
        return this.userDao.insertUser(users);
    }

    @Override
    public List<User> getAllUserBySid(Integer sid) {
        return this.userDao.getAllUserBySid(sid);}
        @Override
    public List<User> getAllUser() {
        return this.userDao.getAllUser();
    }
}
